<?php
class MyXmlReader {

private $stateList = array();
private $pincodes = array();

public static function getInstance()
    {
        static $inst = null;
        if ($inst === null) {
            $inst = new MyXmlReader();
        }
        return $inst;
    }

    /**
     * Private constructor so nobody else can instance it
     *
     */
    private function __construct(){
		$xml = simplexml_load_file("states.xml");
		foreach($xml->children() as $state){
			$name = $state['name'];
			$pincodebegins = $state['pincodebegins'];
			$cityList =array();
			foreach($state->children() as $city){	
				array_push($cityList,$city);
			}
			$temparray  = array("{$name}" => $cityList);
			$this->stateList = array_merge($this->stateList,$temparray);
			
		}
    }

	/**
	* Returns the list of all stored State names
	*
	*/
	public function getStates(){
		return array_keys($this->stateList);
	}
	
	/**
	* Returns a list of all cities for a particular state 
	*
	*/	
	public function getCities($stateName){
		return $this->stateList[ucwords(strtolower(trim($stateName)))];
	}
		
	public function getCsv($arrayList){
	$csv = "";
	foreach($arrayList as $value){
		$csv=$csv.$value.",";
		}
	return trim($csv, ",");	
	}
}


?>